home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Resources / Burning & Media / GB-PVR 1.2.13 / GBPVR10213.msi / Cabs.w1.cab / Details2.aspx.cs177 < prev    next >
Text File  |  2008-03-12  |  48KB  |  1,069 lines

  1. using System;
  2. using System.Collections;
  3. using System.Data.Common;
  4. using System.IO;
  5. using System.Text.RegularExpressions;
  6. using System.Web.Caching;
  7. using System.Web.UI.HtmlControls;
  8. using System.Xml;
  9. using System.Threading;
  10. using System.Web;
  11. using GBPVR.Public;
  12. using GBPVRSchedule;
  13. using gbweb.classes;
  14.  
  15. namespace gbweb
  16. {
  17.     /// <summary>
  18.     /// Summary description for Details.
  19.     /// </summary>
  20.     public partial class Details2 : System.Web.UI.Page
  21.     {
  22.  
  23.         private Settings guideParams;
  24.         protected string programUniqueIdentifier;
  25.     
  26.         protected void Page_Load(object sender, EventArgs e)
  27.         {
  28.             getTheme();
  29.             guideParams = Global.Settings;
  30.             ERROR_MESSAGE.Visible = false;
  31.  
  32.             if (!IsPostBack) 
  33.             {
  34.                 Schedule scheduleHelper = Global.Schedule;
  35.                 Programme programme = null;
  36.                 recordButs_UpdateRecordingTime.Visible = false;
  37.  
  38.                 // if this show was already scheduled, view=cancel would have been passed in
  39.                 ScheduledRecording scheduledRecording = null;
  40.                 
  41.                 string recorded_quality = string.Empty;
  42.  
  43.                 //If there is a parm of rid it means that the show is alredy been recorded
  44.                 if (Request.Params["rid"] != null)
  45.                 {
  46.                     recordingOptionsPanel.Visible = false;
  47.                     spanRecordCancel.InnerText = "Recording Not Found!";
  48.                     lnkRecordCancel.CommandName = "cancel";
  49.                     //Since we are looking at a recorded show the user should be able to see the Stream Now button
  50.                     streamNow.Visible = true;
  51.  
  52.                     scheduledRecording =
  53.                         scheduleHelper.GetScheduledRecordingByOID(Convert.ToInt32(Request.Params["rid"]));
  54.  
  55.                     //If the scheduledRecoding is not null it means that the programme is already scheduled
  56.                     if (scheduledRecording != null)
  57.                     {
  58.                         prePadding.Text = scheduledRecording.getPrePadMinutes().ToString();
  59.                         postPadding.Text = scheduledRecording.getPostPadMinutes().ToString();
  60.  
  61.                         watchLink.PostBackUrl =
  62.                             Download.GetDownloadUrl(false, false, Convert.ToInt32(Request.Params["rid"]));
  63.                         watchLink.Visible = false;
  64.                         // reload recording list
  65.                         switch (scheduledRecording.getQualitySetting())
  66.                         {
  67.                             case (int) Schedule.Quality.Low:
  68.                                 recorded_quality = "Low";
  69.                                 newQuality.SelectedValue = "Low";
  70.                                 break;
  71.                             case (int) Schedule.Quality.Medium:
  72.                                 recorded_quality = "Medium";
  73.                                 newQuality.SelectedValue = "Medium";
  74.                                 break;
  75.                             case (int) Schedule.Quality.High:
  76.                                 recorded_quality = "High";
  77.                                 newQuality.SelectedValue = "High";
  78.                                 break;
  79.                             case (int) Schedule.Quality.Custom1:
  80.                                 recorded_quality = "Custom 1";
  81.                                 newQuality.SelectedValue = "Custom1";
  82.                                 break;
  83.                             case (int) Schedule.Quality.Custom2:
  84.                                 recorded_quality = "Custom 2";
  85.                                 newQuality.SelectedValue = "Custom2";
  86.                                 break;
  87.                             case (int) Schedule.Quality.LiveTV:
  88.                                 recorded_quality = "LiveTV";
  89.                                 newQuality.SelectedValue = "LiveTV";
  90.                                 break;
  91.                             default:
  92.                                 recorded_quality = string.Empty;
  93.                                 newQuality.SelectedValue = string.Empty;
  94.                                 break;
  95.                         }
  96.                         recordingQuality.Text = recorded_quality;
  97.                         switch (scheduledRecording.getRecordingStatus())
  98.                         {
  99.                             case ScheduledRecording.STATUS_PENDING:
  100.                                 lnkRecordCancel.CssClass = "but_Cancel";
  101.                                 spanRecordCancel.InnerText = "Cancel Recording";
  102.                                 padStart.Text = Convert.ToString(scheduledRecording.getPrePadMinutes());
  103.                                 padEnd.Text = Convert.ToString(scheduledRecording.getPostPadMinutes());
  104.                                 recordButs_UpdateRecordingTime.Visible = true;
  105.                                 break;
  106.                             case ScheduledRecording.STATUS_IN_PROGRESS:
  107.                                 lnkRecordCancel.CssClass = "but_Cancel";
  108.                                 spanRecordCancel.InnerText = "Cancel Recording";
  109.                                 padStart.Text = Convert.ToString(scheduledRecording.getPrePadMinutes());
  110.                                 padEnd.Text = Convert.ToString(scheduledRecording.getPostPadMinutes());
  111.                                 recordButs_UpdateRecordingTime.Visible = true;
  112.                                 watchLink.Visible = true;
  113.                                 break;
  114.                             case ScheduledRecording.STATUS_COMPLETED:
  115.                                 lnkRecordCancel.CssClass = "but_DeleteRecording";
  116.                                 spanRecordCancel.InnerText = "Delete Recording";
  117.                                 watchLink.Visible = true;
  118.                                 break;
  119.                             case ScheduledRecording.STATUS_COMPLETED_WITH_ERROR:
  120.                                 lnkRecordCancel.CssClass = "but_DeleteRecording";
  121.                                 spanRecordCancel.InnerText = "Delete Recording";
  122.                                 break;
  123.                             case ScheduledRecording.STATUS_CONFLICT:
  124.                                 lnkRecordCancel.CssClass = "but_Cancel";
  125.                                 spanRecordCancel.InnerText = "Cancel Recording";
  126.                                 break;
  127.                             case ScheduledRecording.STATUS_PLACE_HOLDER:
  128.                                 lnkRecordCancel.CssClass = "but_Cancel";
  129.                                 spanRecordCancel.InnerText = "Cancel Recording";
  130.                                 break;
  131.                             case ScheduledRecording.STATUS_DELETED:
  132.                                 lnkRecordCancel.CssClass = "but_RecordThisEpisode";
  133.                                 spanRecordCancel.InnerText = "Record This Episode";
  134.                                 break;
  135.                             default:
  136.                                 lnkRecordCancel.CssClass = "but_RecordThisEpisode";
  137.                                 spanRecordCancel.InnerText = "Unknown Status!";
  138.                                 break;
  139.                         }
  140.                     }
  141.                     //Populate the programme object with the programme info
  142.                     if (Request.Params["id"] != null)
  143.                     {
  144.                         programme = scheduleHelper.GetProgrammeByOID(int.Parse(Request.Params["id"]));
  145.                     }
  146.                         //The show being viewed has not yet been set to record
  147.                     else
  148.                     {
  149.                         programme = null;
  150.                     }
  151.                 }
  152.                 else
  153.                 {
  154.                     spanRecordCancel.InnerText = "Record This Episode";
  155.                     lnkRecordCancel.CommandName = "record";
  156.                     programme = scheduleHelper.GetProgrammeByOID(int.Parse(Request.Params["id"]));
  157.                     XmlNode pre = Global.Config.SelectSingleNode("/settings/PreShowPadding");
  158.                     XmlNode post = Global.Config.SelectSingleNode("/settings/PostShowPadding");
  159.                     prePadding.Text = pre.InnerText;
  160.                     postPadding.Text = post.InnerText;
  161.                 }
  162.  
  163.                 if (programme != null)
  164.                 {
  165.                     //Check to see if the user has VLC installed to do streaming
  166.                     bool strmAllowed = File.Exists(Path.Combine(guideParams.strmVLCLoc, "vlc.exe"));
  167.                     if (strmAllowed)
  168.                     {
  169.                         //If the programme is in the current time period (it is airing now) or it was recorded previously then the user can Stream Now
  170.                         if ((programme.getStartTime() <= DateTime.Now &&
  171.                              programme.getEndTime() > DateTime.Now.AddMinutes(1)) ||
  172.                             (Request.Params["rid"] != null && programme.getStartTime() <= DateTime.Now))
  173.                         {
  174.                             streamLink.Visible = true;
  175.                         }
  176.                         else
  177.                         {
  178.                             streamLink.Visible = false;
  179.                         }
  180.                     }
  181.                     else
  182.                     {
  183.                         streamLink.Visible = false;
  184.                     }
  185.  
  186.                     //If the programme was already recorded show the button to be able to download/watch the recording
  187.                     //If the programme is still recording you can not see the button.
  188.                     if (scheduledRecording != null && programme.getStartTime() <= DateTime.Now &&
  189.                         programme.getEndTime() <= DateTime.Now)
  190.                     {
  191.                         watchLink.Visible = true;
  192.                     }
  193.                     else
  194.                     {
  195.                         watchLink.Visible = false;
  196.                     }
  197.  
  198.                     //Show programme details
  199.                     showTitle.Text = programme.getTitle();
  200.                     programUniqueIdentifier = programme.getUniqueProgrammeIdentifier();
  201.                     showSubTitle.Text = programme.getSubTitle();
  202.  
  203.                     //If the subtitle is empty do not show the search this episode link
  204.                     if (showSubTitle.Text.Length == 0)
  205.                     {
  206.                         episodeSearch.Visible = false;
  207.                         EPISODE_SUBTITLE.Visible = false;
  208.                     }
  209.  
  210.                     showDescription.Text = DetailDisplay2.getDetailDisplay(programme);
  211.                     if (recorded_quality != string.Empty)
  212.                         showDescription.Text += "<br> Recording Quality: " + recordingQuality.Text;
  213.  
  214.                     divUniqueID.Visible = programUniqueIdentifier.Length > 0;
  215.  
  216.                     showStartDate.Text = programme.getStartTime().ToLongDateString();
  217.  
  218.                     //If the programme being viewed is already set to record or is recorded then we want to pull the end time
  219.                     //from the recording rather than how the program was listed on the EPG.
  220.                     if (scheduledRecording != null)
  221.                     {
  222.                         showTimes.Text = scheduledRecording.getStartTime().ToShortTimeString() + " - " +
  223.                                          scheduledRecording.getEndTime().ToShortTimeString();
  224.                     }
  225.                     else
  226.                     {
  227.                         showTimes.Text = programme.getStartTime().ToShortTimeString() + " - " +
  228.                                          programme.getEndTime().ToShortTimeString();
  229.                     }
  230.  
  231.                     //Setup the channel display info
  232.                     Channel channel = scheduleHelper.GetChannelByOID(programme.getChannelOID());
  233.                     string channelName = channel.getName();
  234.                     if (channelName.StartsWith(channel.getChannelNumber().ToString()))
  235.                         // cosmetic stuff for my american friends
  236.                     {
  237.                         channelName = channelName.Substring(channel.getChannelNumber().ToString().Length);
  238.                     }
  239.                     showChannelName.Text = channelName;
  240.                     showChannelNumber.Text = Convert.ToString(channel.getChannelNumber());
  241.                     string channelIcon =
  242.                         GetChannelIcon(channel.getChannelNumber(), new string[] {channel.getName(), channelName});
  243.                     if (channelIcon != null)
  244.                     {
  245.                         CHANNEL_ICON.InnerHtml = "<img src=\"" +
  246.                                                  Download.GetDownloadUrl(false, true, Download.InternalFiles.ChannelIcon,
  247.                                                                          Server.UrlEncode(channelIcon)) +
  248.                                                  "\" alt=\"\" width=\"67\" height=\"50\" hspace=\"0\" vspace=\"0\" border=\"1\" runat=\"server\">";
  249.                     }
  250.  
  251.  
  252.                     //Set the default recording Quality
  253.                     quality.SelectedValue = guideParams.recordingQuality;
  254.                     TimeSpan span = programme.getStartTime() - DateTime.Now;
  255.                     if (span.Minutes >= 0)
  256.                     {
  257.                         reminderButton.Text = "Set Reminder";
  258.                         ArrayList reminders = scheduleHelper.GetReminderList();
  259.                         foreach (Programme pgm in reminders)
  260.                         {
  261.                             if (pgm.getOID() == programme.getOID())
  262.                             {
  263.                                 reminderButton.Text = "Kill Reminder";
  264.                             }
  265.                         }
  266.                     }
  267.                     else
  268.                     {
  269.                         reminderButton.Visible = false;
  270.                     }
  271.                 }
  272.                 else
  273.                 {
  274.                     streamNow.Visible = false;
  275.                     reminderButton.Visible = false;
  276.                     showStartDate.Text = "Season Recording";
  277.                     subTitlePanel.Visible = false;
  278.                     descriptionPanel.Visible = false;
  279.                     divUniqueID.Visible = false;
  280.                     recordingOptionsPanel.Visible = true;
  281.                     radioDay.Visible = false;
  282.                     radioTime.Visible = false;
  283.  
  284.                     if (scheduledRecording != null)
  285.                     {
  286.                         DAYS_LIST.Visible = true;
  287.  
  288.                         showTimes.Text = scheduledRecording.getStartTime().ToShortTimeString() + " - " +
  289.                                          scheduledRecording.getEndTime().ToShortTimeString();
  290.                         showTitle.Text = scheduledRecording.getFileName();
  291.         
  292.                         checkedDays_0.Attributes.Add("disabled", "disabled");
  293.                         checkedDays_1.Attributes.Add("disabled", "disabled");
  294.                         checkedDays_2.Attributes.Add("disabled", "disabled");
  295.                         checkedDays_3.Attributes.Add("disabled", "disabled");
  296.                         checkedDays_4.Attributes.Add("disabled", "disabled");
  297.                         checkedDays_5.Attributes.Add("disabled", "disabled");
  298.                         checkedDays_6.Attributes.Add("disabled", "disabled");
  299.  
  300.                         int day_mask = scheduleHelper.getSeasonDayMask(scheduledRecording);
  301.  
  302.                         if (day_mask != -1)
  303.                         {
  304.                             if ((day_mask & ReoccuringRecordingExtras.DAY_SUNDAY) > 0)
  305.                             {
  306.                                 checkedDays_6.Checked = true;
  307.                             }
  308.  
  309.                             if ((day_mask & ReoccuringRecordingExtras.DAY_SATURDAY) > 0)
  310.                             {
  311.                                 checkedDays_5.Checked = true;
  312.                             }
  313.  
  314.                             if ((day_mask & ReoccuringRecordingExtras.DAY_FRIDAY) > 0)
  315.                             {
  316.                                 checkedDays_4.Checked = true;
  317.                             }
  318.  
  319.                             if ((day_mask & ReoccuringRecordingExtras.DAY_THURSDAY) > 0)
  320.                             {
  321.                                 checkedDays_3.Checked = true;
  322.                             }
  323.  
  324.                             if ((day_mask & ReoccuringRecordingExtras.DAY_WEDNESDAY) > 0)
  325.                             {
  326.                                 checkedDays_2.Checked = true;
  327.                             }
  328.  
  329.                             if ((day_mask & ReoccuringRecordingExtras.DAY_TUESDAY) > 0)
  330.                             {
  331.                                 checkedDays_1.Checked = true;
  332.                             }
  333.  
  334.                             if ((day_mask & ReoccuringRecordingExtras.DAY_MONDAY) > 0)
  335.                             {
  336.                                 checkedDays_0.Checked = true;
  337.                             }
  338.                         }
  339.                     }
  340.                     else
  341.                     {
  342.                         DAYS_LIST.Visible = false;
  343.                         showTimes.Text = string.Empty;
  344.                         showTitle.Text = string.Empty;
  345.                     }
  346.  
  347.                     keepRecordingsInfo.Visible = false;
  348.  
  349.                     spanRecordCancel.InnerText = "Update Season Recording";
  350.                     lnkRecordCancel.CommandName = "update";
  351.  
  352.                     //Setup the channel display info
  353.                     Channel channel = scheduleHelper.GetChannelByOID(scheduledRecording.getChannelOID());
  354.                     string channelName = channel.getName();
  355.                     if (channelName.StartsWith(channel.getChannelNumber().ToString()))
  356.                     // cosmetic stuff for my american friends
  357.                     {
  358.                         channelName = channelName.Substring(channel.getChannelNumber().ToString().Length);
  359.                     }
  360.                     showChannelName.Text = channelName;
  361.                     showChannelNumber.Text = Convert.ToString(channel.getChannelNumber());
  362.                     string channelIcon =
  363.                         GetChannelIcon(channel.getChannelNumber(), new string[] { channel.getName(), channelName });
  364.                     if (channelIcon != null)
  365.                     {
  366.                         CHANNEL_ICON.InnerHtml = "<img src=\"" +
  367.                                                  Download.GetDownloadUrl(false, true, Download.InternalFiles.ChannelIcon,
  368.                                                                          Server.UrlEncode(channelIcon)) +
  369.                                                  "\" alt=\"\" width=\"67\" height=\"50\" hspace=\"0\" vspace=\"0\" border=\"1\" runat=\"server\">";
  370.                     }
  371.  
  372.                     switch ((Schedule.Quality)scheduledRecording.getQualitySetting())
  373.                     {
  374.                         case Schedule.Quality.High:
  375.                             quality.SelectedValue = "High";
  376.                             newQuality.SelectedValue = "High";
  377.                             break;
  378.  
  379.                         case Schedule.Quality.Medium:
  380.                             quality.SelectedValue = "Medium";
  381.                             newQuality.SelectedValue = "Medium";
  382.                             break;
  383.  
  384.                         case Schedule.Quality.Low:
  385.                             quality.SelectedValue = "Low";
  386.                             newQuality.SelectedValue = "Low";
  387.                             break;
  388.  
  389.                         case Schedule.Quality.Custom1:
  390.                             quality.SelectedValue = "Custom1";
  391.                             newQuality.SelectedValue = "Custom1";
  392.                             break;
  393.  
  394.                         case Schedule.Quality.Custom2:
  395.                             quality.SelectedValue = "Custom2";
  396.                             newQuality.SelectedValue = "Custome2";
  397.                             break;
  398.                     }
  399.  
  400.                     radioTime.Items[0].Enabled = false;
  401.                     if (scheduledRecording.getStartTime().Year != 0001)
  402.                     {
  403.                         radioTime.SelectedValue = "thisTime";
  404.                     }
  405.                     else
  406.                     {
  407.                         radioTime.SelectedValue = "anyTime";
  408.                     }
  409.  
  410.                     prePadding.Text = scheduledRecording.getPrePadMinutes().ToString();
  411.                     postPadding.Text = scheduledRecording.getPostPadMinutes().ToString();
  412.                     
  413.                 }
  414.  
  415.                 //Guest Users do not get access to initiatie, delete or cancel recordings. 
  416.                 lnkRecordCancel.Visible = Convert.ToBoolean((string)Session["NotGuestUser"]);
  417.                 if (Request.Params["rid"] != null && recordingOptionsPanel.Visible)
  418.                 {
  419.                     recordingOptionsPanel.Visible = Convert.ToBoolean((string)Session["NotGuestUser"]);
  420.                 }
  421.             }
  422.         }
  423.  
  424.         protected void lnkRecordCancel_Click(object sender, EventArgs e)
  425.         {
  426.             Schedule scheduleHelper = Global.Schedule;
  427.             Programme programme = null;
  428.             if (Request.Params["id"] != null && lnkRecordCancel.CommandName != "cancel")
  429.             {
  430.                 programme = scheduleHelper.GetProgrammeByOID(int.Parse(Request.Params["id"]));
  431.                 if (Convert.ToDouble(extendMinutes2.Text) != 0)
  432.                 {
  433.                     //Add the number of minutes that was entered to the end time of the recording to set the new end time
  434.                     DateTime newEndDate =
  435.                         programme.getEndTime().AddMinutes(Convert.ToDouble(extendMinutes2.Text));
  436.                     //Set the new end time for the recording
  437.                     programme.setEndTime(newEndDate);
  438.                 }
  439.             }
  440.             bool scheduleReturn = true;
  441.            
  442.             //First we need to validate the user entered valid data
  443.             Regex numerics = new Regex("[0-9]");
  444.             bool validNumbers = true;
  445.             validNumbers = numerics.IsMatch(keepRecordings.Text);
  446.             if (validNumbers) validNumbers = numerics.IsMatch(prePadding.Text);
  447.             if (validNumbers) validNumbers = numerics.IsMatch(postPadding.Text);
  448.             if (validNumbers) validNumbers = numerics.IsMatch(extendMinutes2.Text);
  449.  
  450.             if (!validNumbers)
  451.             {
  452.                 errorMessage.Text = "Must enter valid numbers 0-9 in pad fields, extend end time and recordings to keep fields.";
  453.                 ERROR_MESSAGE.Visible = true;
  454.                 return;
  455.             }
  456.  
  457.             if (lnkRecordCancel.CommandName == "record")
  458.             {
  459.                 Schedule.Quality quality = 0;
  460.                 int prePad = Convert.ToInt32(prePadding.Text);
  461.                 int postPad = Convert.ToInt32(postPadding.Text);
  462.                 switch (Request.Params["quality"].ToLower())
  463.                 {
  464.                     case "high":
  465.                         quality = Schedule.Quality.High;
  466.                         break;
  467.  
  468.                     case "medium":
  469.                         quality = Schedule.Quality.Medium;
  470.                         break;
  471.  
  472.                     case "low":
  473.                         quality = Schedule.Quality.Low;
  474.                         break;
  475.  
  476.                     case "custom1":
  477.                         quality = Schedule.Quality.Custom1;
  478.                         break;
  479.  
  480.                     case "custom2":
  481.                         quality = Schedule.Quality.Custom2;
  482.                         break;
  483.                 }
  484.  
  485.                 if (radioTime.SelectedValue == "once")        
  486.                 {
  487.                     // schedule one-off recording
  488.                     Schedule myschedule = Global.Schedule;
  489.                     scheduleReturn = myschedule.ScheduleOnce(programme, quality, prePad, postPad);
  490.                     if (scheduleReturn)
  491.                     {
  492.                         // build up a list of the recording we already know about
  493.                         IDictionary knownRecordings = scheduleHelper.LoadKnownRecordings();
  494.                         if (!knownRecordings.Contains(programme.getOID()))
  495.                         {
  496.                             scheduleReturn = false;
  497.                         }
  498.                     }
  499.                 }
  500.                 else
  501.                 {
  502.                     //Schedule Season Recordings
  503.                     //Set the max number of recordings to keep for the show
  504.                     int keepnumRecordings     = ReoccuringRecordingExtras.KEEP_ALL_FILES;
  505.                     if (keepRecordings.Text.ToString() != null)
  506.                     {
  507.                         try
  508.                         {
  509.                             keepnumRecordings     = Convert.ToInt32(keepRecordings.Text);
  510.                         }
  511.                         catch
  512.                         {
  513.                             keepnumRecordings     = ReoccuringRecordingExtras.KEEP_ALL_FILES;
  514.                         }
  515.                     }
  516.                     else
  517.                     {
  518.                         keepnumRecordings     = ReoccuringRecordingExtras.KEEP_ALL_FILES;
  519.                     }
  520.                     
  521.                     Schedule myschedule = Global.Schedule;
  522.  
  523.                     if (radioTime.SelectedValue == "thisTime")
  524.                     {
  525.                         // schedule season recording for any day and this time
  526.                         if (radioDay.SelectedValue == "anyDay")
  527.                         {
  528.                             scheduleReturn = myschedule.ScheduleThisTime(programme, quality, Schedule.DayType.SheduleAnyDay, keepnumRecordings, Schedule.RecType.Season, prePad, postPad);
  529.                             if (scheduleReturn)
  530.                             {
  531.                                 // build up a list of the recording we already know about
  532.                                 IDictionary knownRecordings = scheduleHelper.LoadKnownRecordings();
  533.                                 if (!knownRecordings.Contains(programme.getOID()))
  534.                                 {
  535.                                     scheduleReturn = false;
  536.                                 }
  537.                             }
  538.                         }
  539.                         // schedule season recording for only this day and this time
  540.                         else if (radioDay.SelectedValue == "thisDay")
  541.                         {
  542.                             scheduleReturn = myschedule.ScheduleThisTime(programme, quality, Schedule.DayType.SheduleThisDay, keepnumRecordings, Schedule.RecType.Season, prePad, postPad);
  543.                             if (scheduleReturn)
  544.                             {
  545.                                 // build up a list of the recording we already know about
  546.                                 IDictionary knownRecordings = scheduleHelper.LoadKnownRecordings();
  547.                                 if (!knownRecordings.Contains(programme.getOID()))
  548.                                 {
  549.                                     scheduleReturn = false;
  550.                                 }
  551.                             }
  552.                         }
  553.                         // schedule season recording for the selected days and this time
  554.                         else
  555.                         {
  556.                             //Validate that the person selected at least one day to record
  557.                             if (!checkedDays_0.Checked && !checkedDays_1.Checked && !checkedDays_2.Checked &&
  558.                                 !checkedDays_3.Checked && !checkedDays_4.Checked && !checkedDays_5.Checked &&
  559.                                 !checkedDays_6.Checked)
  560.                             {
  561.                                 errorMessage.Text = "Must select at least one day for Specif Day(s) scheduling";
  562.                                 ERROR_MESSAGE.Visible = true;
  563.                                 return;
  564.                             }
  565.                             
  566.                             ArrayList dayList = new ArrayList();
  567.                             // Iterate through the Items collection of the checkedDays 
  568.                             // control and create the correct number for the season recording.
  569.                                 if (checkedDays_0.Checked)
  570.                                 {
  571.                                     dayList.Add(Schedule.Day.Monday);
  572.                                 }
  573.                                 if (checkedDays_1.Checked)
  574.                                 {
  575.                                     dayList.Add(Schedule.Day.Tuesday);
  576.                                 }
  577.                                 if (checkedDays_2.Checked)
  578.                                 {
  579.                                     dayList.Add(Schedule.Day.Wednesday);
  580.                                 }
  581.                                 if (checkedDays_3.Checked)
  582.                                 {
  583.                                     dayList.Add(Schedule.Day.Thursday);
  584.                                 }
  585.                                 if (checkedDays_4.Checked)
  586.                                 {
  587.                                     dayList.Add(Schedule.Day.Friday);
  588.                                 }
  589.                                 if (checkedDays_5.Checked)
  590.                                 {
  591.                                     dayList.Add(Schedule.Day.Saturday);
  592.                                 }
  593.                                 if (checkedDays_6.Checked)
  594.                                 {
  595.                                     dayList.Add(Schedule.Day.Sunday);
  596.                                 }
  597.                             
  598.                             scheduleReturn = myschedule.ScheduleThisTime(programme, quality, Schedule.DayType.SheduleSpecificDays, keepnumRecordings, dayList, Schedule.RecType.Season, prePad, postPad);
  599.                             if (scheduleReturn)
  600.                             {
  601.                                 // build up a list of the recording we already know about
  602.                                 IDictionary knownRecordings = scheduleHelper.LoadKnownRecordings();
  603.                                 if (!knownRecordings.Contains(programme.getOID()))
  604.                                 {
  605.                                     scheduleReturn = false;
  606.                                 }
  607.                             }
  608.                         }
  609.                     }
  610.                     else
  611.                     {
  612.                         // schedule season recording for any day any time
  613.                         if (radioDay.SelectedValue == "anyDay")
  614.                         {
  615.                             scheduleReturn = myschedule.ScheduleAnyTime(programme, quality, Schedule.DayType.SheduleAnyDay, keepnumRecordings, Schedule.RecType.Season, prePad, postPad);
  616.                             if (scheduleReturn)
  617.                             {
  618.                                 // build up a list of the recording we already know about
  619.                                 IDictionary knownRecordings = scheduleHelper.LoadKnownRecordings();
  620.                                 if (!knownRecordings.Contains(programme.getOID()))
  621.                                 {
  622.                                     scheduleReturn = false;
  623.                                 }
  624.                             }
  625.                         }
  626.                             // schedule season recording for only this day and this time
  627.                         else if (radioDay.SelectedValue == "thisDay")
  628.                         {
  629.                             scheduleReturn = myschedule.ScheduleAnyTime(programme, quality, Schedule.DayType.SheduleThisDay, keepnumRecordings, Schedule.RecType.Season, prePad, postPad);
  630.                             if (scheduleReturn)
  631.                             {
  632.                                 // build up a list of the recording we already know about
  633.                                 IDictionary knownRecordings = scheduleHelper.LoadKnownRecordings();
  634.                                 if (!knownRecordings.Contains(programme.getOID()))
  635.                                 {
  636.                                     scheduleReturn = false;
  637.                                 }
  638.                             }
  639.                         }
  640.                             // schedule season recording for the selected days and this time
  641.                         else
  642.                         {
  643.                             ArrayList dayList = new ArrayList();
  644.  
  645.                             //Validate that the person selected at least one day to record
  646.                             if (!checkedDays_0.Checked && !checkedDays_1.Checked && !checkedDays_2.Checked &&
  647.                                 !checkedDays_3.Checked && !checkedDays_4.Checked && !checkedDays_5.Checked &&
  648.                                 !checkedDays_6.Checked)
  649.                             {
  650.                                 errorMessage.Text = "Must select at least one day for Specif Day(s) scheduling";
  651.                                 ERROR_MESSAGE.Visible = true;
  652.                                 return;
  653.                             }
  654.                             // Iterate through the Items collection of the checkedDays 
  655.                             // control and create the correct number for the season recording.
  656.  
  657.                             if (checkedDays_0.Checked)
  658.                             {
  659.                                 dayList.Add(Schedule.Day.Monday);
  660.                             }
  661.                             if (checkedDays_1.Checked)
  662.                             {
  663.                                 dayList.Add(Schedule.Day.Tuesday);
  664.                             }
  665.                             if (checkedDays_2.Checked)
  666.                             {
  667.                                 dayList.Add(Schedule.Day.Wednesday);
  668.                             }
  669.                             if (checkedDays_3.Checked)
  670.                             {
  671.                                 dayList.Add(Schedule.Day.Thursday);
  672.                             }
  673.                             if (checkedDays_4.Checked)
  674.                             {
  675.                                 dayList.Add(Schedule.Day.Friday);
  676.                             }
  677.                             if (checkedDays_5.Checked)
  678.                             {
  679.                                 dayList.Add(Schedule.Day.Saturday);
  680.                             }
  681.                             if (checkedDays_6.Checked)
  682.                             {
  683.                                 dayList.Add(Schedule.Day.Sunday);
  684.                             }
  685.  
  686.                             scheduleReturn = myschedule.ScheduleAnyTime(programme, quality, Schedule.DayType.SheduleSpecificDays, keepnumRecordings, dayList, Schedule.RecType.Season, prePad, postPad);
  687.                             if (scheduleReturn)
  688.                             {
  689.                                 // build up a list of the recording we already know about
  690.                                 IDictionary knownRecordings = scheduleHelper.LoadKnownRecordings();
  691.                                 if (!knownRecordings.Contains(programme.getOID()))
  692.                                 {
  693.                                     scheduleReturn = false;
  694.                                 }
  695.                             }
  696.                         }
  697.                     }
  698.                 }
  699.  
  700.                 if (scheduleReturn)
  701.                 {
  702.                     // close popup details window
  703.                     ClientScript.RegisterStartupScript(typeof(String), "startupScript", "<script language=JavaScript>reloadAndClose();</script>", false);
  704.                 }
  705.                 else
  706.                 {
  707.                     errorMessage.Text = "Recording Failed!";
  708.                     ERROR_MESSAGE.Visible = true;
  709.                 }
  710.             }
  711.             else if (lnkRecordCancel.CommandName == "cancel")
  712.             {
  713.                 ScheduledRecording scheduledRecording = scheduleHelper.GetScheduledRecordingByOID(Convert.ToInt32(Request.Params["rid"]));
  714.                 if (scheduledRecording != null)
  715.                 {
  716.                     scheduleHelper.CancelScheduledRecording(scheduledRecording);
  717.                 }
  718.                 ClientScript.RegisterStartupScript(typeof(String), "startupScript", "<script language=JavaScript>reloadAndClose();</script>", false);
  719.             }
  720.             else if (lnkRecordCancel.CommandName == "update")
  721.             {
  722.                 //Create a scheduled recording object of the programme being viewed so we have something to modify
  723.                 ScheduledRecording scheduledRecording = scheduleHelper.GetScheduledRecordingByOID(Convert.ToInt32(Request.Params["rid"]));
  724.  
  725.                 //Set the pre and post padding minutes
  726.                 scheduledRecording.setPrePadMinutes(Convert.ToInt32(prePadding.Text));
  727.                 scheduledRecording.setPostPadMinutes(Convert.ToInt32(postPadding.Text));
  728.  
  729.                 //Set the quality
  730.                 Schedule.Quality quality = 0;
  731.                 switch (Request.Params["quality"].ToLower())
  732.                 {
  733.                     case "high":
  734.                         quality = Schedule.Quality.High;
  735.                         break;
  736.  
  737.                     case "medium":
  738.                         quality = Schedule.Quality.Medium;
  739.                         break;
  740.  
  741.                     case "low":
  742.                         quality = Schedule.Quality.Low;
  743.                         break;
  744.  
  745.                     case "custom1":
  746.                         quality = Schedule.Quality.Custom1;
  747.                         break;
  748.  
  749.                     case "custom2":
  750.                         quality = Schedule.Quality.Custom2;
  751.                         break;
  752.                 }
  753.                 scheduledRecording.setQualitySetting((int)quality);
  754.  
  755.                 //Use the API to update the recording on the database
  756.                 scheduleHelper.UpdateScheduledRecording(scheduledRecording);
  757.  
  758.                 //Close the window
  759.                 ClientScript.RegisterStartupScript(typeof(String), "startupScript", "<script language=JavaScript>windowClose();</script>", false);
  760.             }
  761.         }
  762.  
  763.         private void getTheme()
  764.         {
  765.             bool use_new_themes = false;
  766.             string themeDir = Server.MapPath(Request.ApplicationPath);
  767.             if (File.Exists(Path.Combine(themeDir, "select_theme.xml")))
  768.             {
  769.                 XmlDocument configThemes = new XmlDocument();
  770.                 configThemes.Load(Path.Combine(themeDir, "select_theme.xml"));
  771.                 XmlNodeList themeConfig = configThemes.SelectNodes("theme_config");
  772.                 foreach (XmlNode themeOpt in themeConfig)
  773.                 {
  774.                     use_new_themes = Convert.ToBoolean(themeOpt.SelectSingleNode("//use_new_themes").InnerText);
  775.                 }
  776.             }
  777.  
  778.             string theme = Convert.ToString(Session["theme"]);
  779.  
  780.             HttpCookie cookie = new HttpCookie("UseNewThemes", use_new_themes.ToString());
  781.             cookie.Expires = DateTime.Now.AddYears(1);
  782.             Response.Cookies.Add(cookie);
  783.  
  784.             if (theme != null && theme != "" && !use_new_themes)
  785.             {
  786.                 return;
  787.             }
  788.             else
  789.             {
  790.                 cookie = Request.Cookies["theme"];
  791.                 if (cookie != null && cookie.Value.Length > 0)
  792.                 {
  793.                     theme = cookie.Value;
  794.                 }
  795.                 else
  796.                 {
  797.                     theme = "Default";
  798.                 }
  799.                 if (use_new_themes)
  800.                 {
  801.                     Session["theme"] = "themes2/" + theme;
  802.                 }
  803.                 else
  804.                 {
  805.                     Session["theme"] = "themes/" + theme;
  806.                 }
  807.                 return;
  808.             }
  809.         }
  810.  
  811.         #region Web Form Designer generated code
  812.         override protected void OnInit(EventArgs e)
  813.         {
  814.             //
  815.             // CODEGEN: This call is required by the ASP.NET Web Form Designer.
  816.             //
  817.             InitializeComponent();
  818.             base.OnInit(e);
  819.         }
  820.         
  821.         /// <summary>
  822.         /// Required method for Designer support - do not modify
  823.         /// the contents of this method with the code editor.
  824.         /// </summary>
  825.         private void InitializeComponent()
  826.         {
  827.         }
  828.         #endregion
  829.  
  830.         protected void LinkButton1_Click(object sender, EventArgs e)
  831.         {
  832.             Schedule scheduleHelper = Global.Schedule;
  833.             ScheduledRecording scheduledRecording_check = scheduleHelper.GetScheduledRecordingByOID(Convert.ToInt32(Request.Params["rid"]));
  834.             if (scheduledRecording_check == null)
  835.             {
  836.                 Programme programme = scheduleHelper.GetProgrammeByOID(int.Parse(Request.Params["id"]));
  837.                 if (Convert.ToDouble(extendMinutes2.Text) != 0)
  838.                 {
  839.                     //Add the number of minutes that was entered to the end time of the recording to set the new end time
  840.                     DateTime newEndDate =
  841.                         programme.getEndTime().AddMinutes(Convert.ToDouble(extendMinutes2.Text));
  842.                     //Set the new end time for the recording
  843.                     programme.setEndTime(newEndDate);
  844.                 }
  845.                 bool scheduleReturn = true;
  846.                 Schedule.Quality quality = 0;
  847.                 int prePad = Convert.ToInt32(prePadding.Text);
  848.                 int postPad = Convert.ToInt32(postPadding.Text);
  849.  
  850.                 switch (Request.Params["quality"].ToLower())
  851.                 {
  852.                     case "high":
  853.                         quality = Schedule.Quality.High;
  854.                         break;
  855.  
  856.                     case "medium":
  857.                         quality = Schedule.Quality.Medium;
  858.                         break;
  859.  
  860.                     case "low":
  861.                         quality = Schedule.Quality.Low;
  862.                         break;
  863.  
  864.                     case "custom1":
  865.                         quality = Schedule.Quality.Custom1;
  866.                         break;
  867.  
  868.                     case "custom2":
  869.                         quality = Schedule.Quality.Custom2;
  870.                         break;
  871.                 }
  872.  
  873.                 Schedule myschedule = Global.Schedule;
  874.                 scheduleReturn = myschedule.ScheduleOnce(programme, quality, prePad, postPad);
  875.  
  876.                 if (scheduleReturn)
  877.                 {
  878.                     Thread.Sleep(5000);
  879.                     IList myScheduledRecordings = scheduleHelper.LoadRecordingSchedule();
  880.                     foreach (ScheduledRecording scheduledRecording in myScheduledRecordings)
  881.                     {
  882.                         if (scheduledRecording.getProgrammeOID() == programme.getOID())
  883.                         {
  884.                             Response.Redirect("public/Player2.aspx?rid=" + scheduledRecording.getOID() + "&type=sn");
  885.                             break;
  886.                         }
  887.                     }
  888.                     errorMessage.Text = "Stream Now Failed!";
  889.                     ERROR_MESSAGE.Visible = true;
  890.                 }
  891.                 else
  892.                 {
  893.                     errorMessage.Text = "Stream Now Failed!";
  894.                     ERROR_MESSAGE.Visible = true;
  895.                 }
  896.             }
  897.             else
  898.             {
  899.                 Response.Redirect("public/Player2.aspx?rid=" + scheduledRecording_check.getOID() + "&type=mr");
  900.             }
  901.         }
  902.  
  903.         protected void reminderButton_Click(object sender, EventArgs e)
  904.         {
  905.             Schedule scheduleHelper = Global.Schedule;
  906.             Programme programme = null;
  907.             programme = scheduleHelper.GetProgrammeByOID(int.Parse(Request.Params["id"]));
  908.             if (reminderButton.Text == "Set Reminder")
  909.             {
  910.                 scheduleHelper.CreateReminder(programme);
  911.                 reminderButton.Text = "Kill Reminder";
  912.             }
  913.             else
  914.             {
  915.                 scheduleHelper.RemoveReminder(programme);
  916.                 reminderButton.Text = "Set Reminder"; 
  917.             }
  918.         }
  919.  
  920.         protected void endTimeUpdate_Click(object sender, EventArgs e)
  921.         {
  922.             //First we need to validate the user entered valid data
  923.             Regex numerics = new Regex("[0-9]");
  924.             bool validNumbers = true;
  925.             validNumbers = numerics.IsMatch(padStart.Text);
  926.             if (validNumbers) validNumbers = numerics.IsMatch(padEnd.Text);
  927.             if (validNumbers) validNumbers = numerics.IsMatch(extendMinutes.Text);
  928.  
  929.             if (!validNumbers)
  930.             {
  931.                 errorMessage.Text = "Must enter valid number 0-9 in pad or extend fields";
  932.                 ERROR_MESSAGE.Visible = true;
  933.                 return;
  934.             }
  935.  
  936.  
  937.             //Create a new schedulehelper
  938.             Schedule scheduleHelper = Global.Schedule;
  939.             
  940.             //Create a scheduled recording object of the programme being viewed so we have something to modify
  941.             ScheduledRecording scheduledRecording = scheduleHelper.GetScheduledRecordingByOID(Convert.ToInt32(Request.Params["rid"]));
  942.             
  943.             //Set the pre and post padding minutes
  944.             scheduledRecording.setPrePadMinutes(Convert.ToInt32(padStart.Text));
  945.             scheduledRecording.setPostPadMinutes(Convert.ToInt32(padEnd.Text));
  946.  
  947.             //Add the number of minutes that was entered to the end time of the recording to set the new end time
  948.             DateTime newEndDate = scheduledRecording.getEndTime().AddMinutes(Convert.ToDouble(extendMinutes.Text));
  949.             //Set the new end time for the recording
  950.             scheduledRecording.setEndTime(newEndDate);
  951.  
  952.             //Set the new Quality
  953.             Schedule.Quality Newquality = 0;
  954.             switch (newQuality.SelectedValue.ToLower())
  955.             {
  956.                 case "high":
  957.                     Newquality = Schedule.Quality.High;
  958.                     break;
  959.  
  960.                 case "medium":
  961.                     Newquality = Schedule.Quality.Medium;
  962.                     break;
  963.  
  964.                 case "low":
  965.                     Newquality = Schedule.Quality.Low;
  966.                     break;
  967.  
  968.                 case "custom1":
  969.                     Newquality = Schedule.Quality.Custom1;
  970.                     break;
  971.  
  972.                 case "custom2":
  973.                     Newquality = Schedule.Quality.Custom2;
  974.                     break;
  975.             }
  976.  
  977.             scheduledRecording.setQualitySetting((int)Newquality);
  978.             
  979.             //USe the API to update the recording on the database
  980.             scheduleHelper.UpdateScheduledRecording(scheduledRecording);
  981.             
  982.             //Close the window
  983.             ClientScript.RegisterStartupScript(typeof(String), "startupScript", "<script language=JavaScript>windowClose();</script>", false);
  984.         }
  985.  
  986.         private static string channelIconPath;
  987.         private static string[] channelIconExtensions;
  988.  
  989.         public string GetChannelIcon(int channelNumber, string[] channelNames)
  990.         {
  991.             // Get the Channel Icon Directory
  992.             if (channelIconPath == null)
  993.             {
  994.                 lock (typeof(Details2))
  995.                 {
  996.                     if (channelIconPath == null)
  997.                     {
  998.                         channelIconPath = Path.Combine(Global.Settings.GetInstallDir(), @"media\ChannelLogos");
  999.                         channelIconExtensions = Global.Settings.channelIconExtensions.Split(',');
  1000.                     }
  1001.                 }
  1002.             }
  1003.  
  1004.             Hashtable channelIconCache = (Hashtable)Cache["channelIconCache"];
  1005.             if (channelIconCache == null)
  1006.             {
  1007.                 lock (typeof(Details2))
  1008.                 {
  1009.                     channelIconCache = (Hashtable)Cache["channelIconCache"];
  1010.                     if (channelIconCache == null)
  1011.                     {
  1012.                         channelIconCache = new Hashtable();
  1013.                         Cache.Add(
  1014.                             "channelIconCache",
  1015.                             channelIconCache,
  1016.                             new CacheDependency(channelIconPath),
  1017.                             //DateTime.MaxValue,
  1018.                             DateTime.Now.AddMinutes(30),
  1019.                             //TimeSpan.Zero,
  1020.                             Cache.NoSlidingExpiration,
  1021.                             CacheItemPriority.Normal,
  1022.                             null);
  1023.                     }
  1024.                 }
  1025.             }
  1026.  
  1027.             if (channelIconCache.ContainsKey(channelNumber))
  1028.             {
  1029.                 return (string)channelIconCache[channelNumber];
  1030.             }
  1031.  
  1032.             lock (channelIconCache)
  1033.             {
  1034.                 if (channelIconCache.ContainsKey(channelNumber))
  1035.                 {
  1036.                     return (string)channelIconCache[channelNumber];
  1037.                 }
  1038.  
  1039.                 string channelIconFile = null;
  1040.                 foreach (string channelName in channelNames)
  1041.                 {
  1042.                     foreach (string channelIconExtension in channelIconExtensions)
  1043.                     {
  1044.                         string cleanName = channelName;
  1045.                         string channelNameWork = channelName;
  1046.                         while (cleanName.Contains("/"))
  1047.                         {
  1048.                             if (channelNameWork.Contains("/"))
  1049.                             {
  1050.                                 cleanName = channelNameWork.Remove(channelNameWork.IndexOf("/"), 1);
  1051.                                 channelNameWork = cleanName;
  1052.                             }
  1053.                         }
  1054.                         string probeFile = cleanName + "." + channelIconExtension;
  1055.                         if (File.Exists(Path.Combine(channelIconPath, probeFile)))
  1056.                         {
  1057.                             channelIconFile = probeFile;
  1058.                             break;
  1059.                         }
  1060.                     }
  1061.                     if (channelIconFile != null) break;
  1062.                 }
  1063.                 channelIconCache[channelNumber] = channelIconFile;
  1064.                 return channelIconFile;
  1065.             }
  1066.         }
  1067.     }
  1068. }
  1069.